package com.qing.shardingjdbc.controller;

import com.qing.shardingjdbc.entity.User;
import com.qing.shardingjdbc.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Random;

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserMapper userMapper;


    @GetMapping("/save")
    public String insert(){
        User user=new User();
        user.setName("AAA"+new Random().nextInt());
        user.setPassword("12456");
        user.setAge(15);
        user.setAddress("上海");
        return "success";
    }

    @GetMapping("/listuser")
    public List<User> listuser() {
        return userMapper.findUsers();
    }
}
